/**
 *====================================================
 * 文件名称: FinanceAuditServiceImpl.java
 * 修订记录：
 * No    日期				作者(操作:具体内容)
 * 1.    2015年09月23日	chenxy(创建:创建文件)
 *====================================================
 * 类描述：(说明未实现或其它不应生成javadoc的内容)
 */
package com.yuexunit.finance.project.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.member.entity.lexicon.AuditStateEnum;
import com.yuexunit.finance.project.entity.SignatureEntity;
import com.yuexunit.finance.seal.entity.lexion.SealTypeEnum;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.persist.annotation.Transactional;
import com.yuexunit.util.DateUtil;

/**
 * @ClassName: FinanceSignatureServiceImpl
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author chenxy
 * @date 2015年09月23日 18:56:17
 */
@Implements(FinanceSignatureService.class)
public class FinanceSignatureServiceImpl implements FinanceSignatureService {
	
	@Override
	@Transactional
	public Long createFinanceGroupEntity(SignatureEntity signatureEntity) {
		signatureEntity.setCreateDateTime(DateUtil.now());
		signatureEntity.setEnabled(Boolean.FALSE);
		PersistUtil.insertOrUpdate(signatureEntity);
		return signatureEntity.getId();
	}

	@Override
	public List<SignatureEntity> inquireFinanceSignatureEntityList(Long enterpriseId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(SignatureEntity.class);
		if (null != enterpriseId) {
			criteria.add(Restrictions.eq("enterpriseId", enterpriseId));
		}
		criteria.add(Restrictions.eq("enabled", Boolean.TRUE));
		criteria.add(Restrictions.eq("auditState", AuditStateEnum.PASS));
		criteria.addOrder(Order.desc("createDateTime"));
		return PersistUtil.get(criteria);
	}
	

	@Override
	public SignatureEntity inquireFinanceSignatureEntity(Long id) {
		return PersistUtil.get(SignatureEntity.class, id);
	}

	@Override
	public SignatureEntity inquireFinanceSignatureEntity(Long enterpriseId, Integer modelType, SealTypeEnum sealType) {
		DetachedCriteria criteria = DetachedCriteria.forClass(SignatureEntity.class);
		criteria.add(Restrictions.eq("enterpriseId", enterpriseId));
		if(modelType != null) {
			criteria.add(Restrictions.eq("modelType", modelType));
		}
		criteria.add(Restrictions.eq("sealType", sealType));
//		criteria.add(Restrictions.eq("auditState", AuditStateEnum.PASS));
		criteria.addOrder(Order.desc("createDateTime"));
		List<SignatureEntity> list=PersistUtil.get(criteria);
		return list != null && list.size()>0 ? list.get(0) : null;
	}

	@Override
	public void updateSignatureEntity(SignatureEntity signatureEntity) {
		PersistUtil.update(signatureEntity);
	}
}
